<!DOCTYPE html>
<html lang=zh>
<head>
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5" />
    <meta name="description" content="css选择器有哪些 id选择器（#myid） 类选择器（.myclassname） 标签选择器（div,h1,p） 后代选择器（h1 p） 相邻后代选择器（子）选择器（ul&gt;li） 兄弟选择器（li~a） 相邻兄弟选择器（li+a） 属性选择器（a[rel&#x3D;”external”]） 伪类选择器（a:hover,li:nth-child） 伪元素选择器（::before、::after） 通配">
<meta property="og:type" content="article">
<meta property="og:title" content="css面试题合集">
<meta property="og:url" content="https://danyuan30.gitee.io/2022/03/05/interview/css/index.html">
<meta property="og:site_name" content="柯里的语法糖">
<meta property="og:description" content="css选择器有哪些 id选择器（#myid） 类选择器（.myclassname） 标签选择器（div,h1,p） 后代选择器（h1 p） 相邻后代选择器（子）选择器（ul&gt;li） 兄弟选择器（li~a） 相邻兄弟选择器（li+a） 属性选择器（a[rel&#x3D;”external”]） 伪类选择器（a:hover,li:nth-child） 伪元素选择器（::before、::after） 通配">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2022-03-05T12:31:10.768Z">
<meta property="article:modified_time" content="2022-03-05T12:31:10.768Z">
<meta property="article:author" content="柯里的语法糖">
<meta property="article:tag" content="css">
<meta property="article:tag" content="面试">
<meta name="twitter:card" content="summary">
    
    
      
        
          <link rel="shortcut icon" href="https://codertzm.oss-cn-chengdu.aliyuncs.com/favicon.ico">
        
      
      
        
          <link rel="icon" type="image/png" href="https://codertzm.oss-cn-chengdu.aliyuncs.com/favicon.ico" sizes="192x192">
        
      
      
        
          <link rel="apple-touch-icon" sizes="180x180" href="https://codertzm.oss-cn-chengdu.aliyuncs.com/favicon.ico">
        
      
    
    <!-- title -->
    <title>css面试题合集</title>
    <!-- styles -->
    
<link rel="stylesheet" href="/css/style.css">

    <!-- persian styles -->
    
    <!-- rss -->
    
    
	<!-- mathjax -->
	
<meta name="generator" content="Hexo 6.0.0"></head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#" aria-label="Menu"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#" aria-label="Menu"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" aria-label="Top" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
        <!--
       --><li><a href="/">首页</a></li><!--
     --><!--
       --><li><a href="/tags/">标签</a></li><!--
     --><!--
       --><li><a href="/categories/">分类</a></li><!--
     --><!--
       --><li><a href="/archives/">归档</a></li><!--
     --><!--
       --><li><a target="_blank" rel="noopener" href="http://github.com/twitzz">项目</a></li><!--
     --><!--
       --><li><a href="/about/">关于</a></li><!--
     --><!--
       --><li><a href="/search/">搜索</a></li><!--
     -->
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" aria-label="上一篇" href="/2022/03/05/frontend/cookie_session_token/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" aria-label="下一篇" href="/2022/03/05/interview/%E5%A6%82%E4%BD%95%E5%86%99%E7%AE%80%E5%8E%86/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" aria-label="返回顶部" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" aria-label="分享文章" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">上一篇</span>
      <span id="i-next" class="info" style="display:none;">下一篇</span>
      <span id="i-top" class="info" style="display:none;">返回顶部</span>
      <span id="i-share" class="info" style="display:none;">分享文章</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.facebook.com/sharer.php?u=https://danyuan30.gitee.io/2022/03/05/interview/css/"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://twitter.com/share?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&text=css面试题合集"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.linkedin.com/shareArticle?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&title=css面试题合集"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://pinterest.com/pin/create/bookmarklet/?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&is_video=false&description=css面试题合集"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=css面试题合集&body=Check out this article: https://danyuan30.gitee.io/2022/03/05/interview/css/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://getpocket.com/save?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&title=css面试题合集"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://reddit.com/submit?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&title=css面试题合集"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.stumbleupon.com/submit?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&title=css面试题合集"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://digg.com/submit?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&title=css面试题合集"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.tumblr.com/share/link?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&name=css面试题合集&description="><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://news.ycombinator.com/submitlink?u=https://danyuan30.gitee.io/2022/03/05/interview/css/&t=css面试题合集"><i class="fab fa-hacker-news " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#css%E9%80%89%E6%8B%A9%E5%99%A8%E6%9C%89%E5%93%AA%E4%BA%9B"><span class="toc-number">1.</span> <span class="toc-text">css选择器有哪些</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#display-%E6%9C%89%E5%93%AA%E4%BA%9B%E5%80%BC%EF%BC%9F%E8%AF%B4%E6%98%8E%E4%BB%96%E4%BB%AC%E7%9A%84%E4%BD%9C%E7%94%A8"><span class="toc-number">2.</span> <span class="toc-text">display 有哪些值？说明他们的作用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%8A%A8%E7%94%BB%E4%B8%8E-js-%E5%8A%A8%E7%94%BB%E5%93%AA%E4%B8%AA%E6%80%A7%E8%83%BD%E6%9B%B4%E5%A5%BD"><span class="toc-number">3.</span> <span class="toc-text">css 动画与 js 动画哪个性能更好</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%AF%B9%E4%B8%80%E4%B8%AA%E9%9D%9E%E5%AE%9A%E9%95%BF%E5%AE%BD%E7%9A%84%E5%9D%97%E7%8A%B6%E5%85%83%E7%B4%A0%E5%A6%82%E4%BD%95%E5%81%9A%E5%9E%82%E7%9B%B4%E6%B0%B4%E5%B9%B3%E5%B1%85%E4%B8%AD"><span class="toc-number">4.</span> <span class="toc-text">css 对一个非定长宽的块状元素如何做垂直水平居中</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E7%94%BB%E4%B8%80%E4%B8%AA%E4%B8%89%E8%A7%92%E5%BD%A2"><span class="toc-number">5.</span> <span class="toc-text">css 如何画一个三角形</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AE%E5%A4%9A%E8%A1%8C%E8%B6%85%E5%87%BA%E6%98%BE%E7%A4%BA%E7%9C%81%E7%95%A5%E5%8F%B7"><span class="toc-number">6.</span> <span class="toc-text">css 如何设置多行超出显示省略号</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AE%E4%B8%80%E8%A1%8C%E8%B6%85%E5%87%BA%E6%98%BE%E7%A4%BA%E7%9C%81%E7%95%A5%E5%8F%B7"><span class="toc-number">7.</span> <span class="toc-text">css 如何设置一行超出显示省略号</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%AF%B9%E4%B8%80%E4%B8%AA%E9%9D%9E%E5%AE%9A%E9%95%BF%E5%AE%BD%E7%9A%84%E5%9D%97%E7%8A%B6%E5%85%83%E7%B4%A0%E5%A6%82%E4%BD%95%E5%81%9A%E5%9E%82%E7%9B%B4%E6%B0%B4%E5%B9%B3%E5%B1%85%E4%B8%AD-1"><span class="toc-number">8.</span> <span class="toc-text">css 对一个非定长宽的块状元素如何做垂直水平居中</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0%E7%9A%84%E6%B0%B4%E5%B9%B3%E5%9E%82%E7%9B%B4%E5%B1%85%E4%B8%AD"><span class="toc-number">9.</span> <span class="toc-text">css 如何实现一个元素的水平垂直居中</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E5%B7%A6%E4%BE%A7%E5%9B%BA%E5%AE%9A-300px%EF%BC%8C%E5%8F%B3%E4%BE%A7%E8%87%AA%E9%80%82%E5%BA%94%E7%9A%84%E5%B8%83%E5%B1%80"><span class="toc-number">10.</span> <span class="toc-text">css 如何实现左侧固定 300px，右侧自适应的布局</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E9%9A%90%E8%97%8F%E9%A1%B5%E9%9D%A2%E4%B8%AD%E6%9F%90%E4%B8%AA%E5%85%83%E7%B4%A0%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E6%B3%95"><span class="toc-number">11.</span> <span class="toc-text">css 隐藏页面中某个元素的几种方法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E4%B8%AD%E2%80%99-%E2%80%99-%E4%B8%8E-%E2%80%98-%E2%80%99-%E9%80%89%E6%8B%A9%E5%99%A8%E6%9C%89%E4%BB%80%E4%B9%88%E4%B8%8D%E5%90%8C"><span class="toc-number">12.</span> <span class="toc-text">css 中’+’ 与 ‘~’ 选择器有什么不同</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E4%B8%AD%E5%85%B3%E4%BA%8E%E9%80%89%E6%8B%A9%E5%99%A8%E7%9A%84%E6%9D%83%E9%87%8D"><span class="toc-number">13.</span> <span class="toc-text">css 中关于选择器的权重</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#flex-%E5%B8%83%E5%B1%80%E4%B8%AD%E7%9A%84-flex-basis-%E4%B8%8E-width-%E6%9C%89%E4%BD%95%E5%8C%BA%E5%88%AB"><span class="toc-number">14.</span> <span class="toc-text">flex 布局中的 flex-basis 与 width 有何区别</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E8%87%AA%E5%AE%9A%E4%B9%89%E6%BB%9A%E5%8A%A8%E6%9D%A1%E7%9A%84%E6%A0%B7%E5%BC%8F"><span class="toc-number">15.</span> <span class="toc-text">css 如何自定义滚动条的样式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E5%AE%B9%E5%99%A8%E4%B8%AD%E5%AD%90%E5%85%83%E7%B4%A0%E4%B8%89%E4%B8%AA%E4%B8%89%E5%88%97%E5%B8%83%E5%B1%80%EF%BC%8C%E5%AD%90%E5%85%83%E7%B4%A0%E4%B8%A4%E4%B8%AA%E5%88%99%E4%B8%A4%E5%88%97%E5%B8%83%E5%B1%80"><span class="toc-number">16.</span> <span class="toc-text">css 如何实现容器中子元素三个三列布局，子元素两个则两列布局</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E7%BD%91%E7%AB%99%E8%AE%BE%E7%BD%AE%E5%AD%97%E4%BD%93%E6%97%B6%EF%BC%8C%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AE%E4%BC%98%E5%85%88%E4%BD%BF%E7%94%A8%E7%B3%BB%E7%BB%9F%E9%BB%98%E8%AE%A4%E5%AD%97%E4%BD%93"><span class="toc-number">17.</span> <span class="toc-text">css 网站设置字体时，如何设置优先使用系统默认字体</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AE%E6%96%B9%E6%A0%BC%E8%83%8C%E6%99%AF"><span class="toc-number">18.</span> <span class="toc-text">css 如何设置方格背景</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BC%AA%E7%B1%BB%E5%92%8C%E4%BC%AA%E5%85%83%E7%B4%A0%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-number">19.</span> <span class="toc-text">伪类和伪元素的区别</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css%E5%AE%9A%E4%BD%8D"><span class="toc-number">20.</span> <span class="toc-text">css定位</span></a></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        css面试题合集
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">柯里的语法糖</span>
      </span>
      
    <div class="postdate">
      
        <time datetime="2022-03-05T12:31:10.768Z" itemprop="datePublished">2022-03-05</time>
        
      
    </div>


      
    <div class="article-category">
        <i class="fas fa-archive"></i>
        <a class="category-link" href="/categories/%E9%9D%A2%E8%AF%95/">面试</a>
    </div>


      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link-link" href="/tags/css/" rel="tag">css</a>, <a class="tag-link-link" href="/tags/%E9%9D%A2%E8%AF%95/" rel="tag">面试</a>
    </div>


    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <h2 id="css选择器有哪些"><a href="#css选择器有哪些" class="headerlink" title="css选择器有哪些"></a>css选择器有哪些</h2><ol>
<li>id选择器（#myid）</li>
<li>类选择器（.myclassname）</li>
<li>标签选择器（div,h1,p）</li>
<li>后代选择器（h1 p）</li>
<li>相邻后代选择器（子）选择器（ul&gt;li）</li>
<li>兄弟选择器（li~a）</li>
<li>相邻兄弟选择器（li+a）</li>
<li>属性选择器（a[rel=”external”]）</li>
<li>伪类选择器（a:hover,li:nth-child）</li>
<li>伪元素选择器（::before、::after）</li>
<li>通配符选择器（*）</li>
</ol>
<h2 id="display-有哪些值？说明他们的作用"><a href="#display-有哪些值？说明他们的作用" class="headerlink" title="display 有哪些值？说明他们的作用"></a>display 有哪些值？说明他们的作用</h2><ul>
<li>block 块类型。默认宽度为父元素宽度，可设置宽高，换行显示。</li>
<li>none 元素不显示，并从文档流中移除。</li>
<li>inline 行内元素类型。默认宽度为内容宽度，不可设置宽高，同行显示。</li>
<li>inline-block 默认宽度为内容宽度，可以设置宽高，同行显示。</li>
<li>list-item 像块类型元素一样显示，并添加样式列表标记。</li>
<li>table 此元素会作为块级表格来显示。</li>
<li>inherit 规定应该从父元素继承display属性的值。</li>
</ul>
<h2 id="css-动画与-js-动画哪个性能更好"><a href="#css-动画与-js-动画哪个性能更好" class="headerlink" title="css 动画与 js 动画哪个性能更好"></a>css 动画与 js 动画哪个性能更好</h2><ul>
<li><p>CSS3 的动画</p>
<ol>
<li><p>在性能上会稍微好一些，浏览器会对 CSS3 的动画做一些优化（比如专门新建一个图层用来跑动画）</p>
</li>
<li><p>代码相对简单</p>
</li>
<li><p>在动画控制上不够灵活</p>
</li>
<li><p>兼容性不好</p>
</li>
<li><p>部分动画功能无法实现（如滚动动画，视差滚动等）</p>
</li>
</ol>
</li>
<li><p>JavaScript 的动画</p>
<p>正好弥补了 css 缺点，控制能力很强，可以单帧的控制、变换，同时写得好完全可以兼容 IE6，并且功能强大。</p>
<p>总结： 对于一些复杂控制的动画，使用 javascript 会比较好。而在实现一些小的交互动效的时候，可以多考虑 CSS</p>
</li>
</ul>
<h2 id="css-对一个非定长宽的块状元素如何做垂直水平居中"><a href="#css-对一个非定长宽的块状元素如何做垂直水平居中" class="headerlink" title="css 对一个非定长宽的块状元素如何做垂直水平居中"></a>css 对一个非定长宽的块状元素如何做垂直水平居中</h2><p>定位：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.parent</span> &#123; </span><br><span class="line">  <span class="attribute">position</span>: relative;</span><br><span class="line">&#125; </span><br><span class="line"><span class="selector-class">.child</span> &#123;</span><br><span class="line">   <span class="attribute">position</span>: absolute; </span><br><span class="line">   <span class="attribute">top</span>: <span class="number">50%</span>; </span><br><span class="line">   <span class="attribute">left</span>: <span class="number">50%</span>; </span><br><span class="line">   <span class="attribute">transform</span>: <span class="built_in">translate</span>(-<span class="number">50%</span>, -<span class="number">50%</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="css-如何画一个三角形"><a href="#css-如何画一个三角形" class="headerlink" title="css 如何画一个三角形"></a>css 如何画一个三角形</h2><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.triangle</span> &#123;</span><br><span class="line">  <span class="attribute">width</span>: <span class="number">0</span>;</span><br><span class="line">  <span class="attribute">border</span>: <span class="number">100px</span> solid transparent;</span><br><span class="line">  <span class="attribute">border-bottom</span>: <span class="number">100px</span> solid <span class="built_in">rgba</span>(<span class="number">66</span>, <span class="number">142</span>, <span class="number">212</span>, <span class="number">0.4</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="css-如何设置多行超出显示省略号"><a href="#css-如何设置多行超出显示省略号" class="headerlink" title="css 如何设置多行超出显示省略号"></a>css 如何设置多行超出显示省略号</h2><p>使用 <code>-webkit-line-clamp</code> 来设置多行超出显示省略号</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">overflow</span>: hidden;</span><br><span class="line"><span class="attribute">display</span>: -webkit-box;</span><br><span class="line">-webkit-box-orient: vertical;</span><br><span class="line">-webkit-line-clamp: <span class="number">2</span>;</span><br></pre></td></tr></table></figure>

<h2 id="css-如何设置一行超出显示省略号"><a href="#css-如何设置一行超出显示省略号" class="headerlink" title="css 如何设置一行超出显示省略号"></a>css 如何设置一行超出显示省略号</h2><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">overflow</span>: hidden;</span><br><span class="line"><span class="attribute">text-overflow</span>: ellipsis;</span><br><span class="line"><span class="attribute">white-space</span>: nowrap;</span><br></pre></td></tr></table></figure>

<h2 id="css-对一个非定长宽的块状元素如何做垂直水平居中-1"><a href="#css-对一个非定长宽的块状元素如何做垂直水平居中-1" class="headerlink" title="css 对一个非定长宽的块状元素如何做垂直水平居中"></a>css 对一个非定长宽的块状元素如何做垂直水平居中</h2><p>通过 css3 中伪类 :nth-child 来实现。</p>
<p>其中 <code>:nth-child(an+b)</code> 匹配下标 { an + b; n = 0, 1, 2, …} 且结果为整数的子元素</p>
<p><code>nth-child(2n)/nth-child(even)</code>: 双行样式<br><code>nth-child(2n+1)/nth-child(odd)</code>: 单行样式</p>
<p>其中 tr 在表格中代表行，实现表格中单双行样式就很简单了：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">tr</span><span class="selector-pseudo">:nth-child</span>(<span class="number">2</span>n) &#123;</span><br><span class="line">  <span class="attribute">background-color</span>: red;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="selector-tag">tr</span><span class="selector-pseudo">:nth-child</span>(<span class="number">2</span>n + <span class="number">1</span>) &#123;</span><br><span class="line">  <span class="attribute">background-color</span>: blue;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>同理：</p>
<p>如何匹配最前三个子元素: <code>:nth-child(-n+3)</code><br>如何匹配最后三个子元素: <code>:nth-last-child(-n+3)</code></p>
<h2 id="css-如何实现一个元素的水平垂直居中"><a href="#css-如何实现一个元素的水平垂直居中" class="headerlink" title="css 如何实现一个元素的水平垂直居中"></a>css 如何实现一个元素的水平垂直居中</h2><p>flex：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">style</span>&gt;</span><span class="css"></span></span><br><span class="line"><span class="css"><span class="selector-tag">body</span> &#123;</span></span><br><span class="line"><span class="css">    <span class="attribute">display</span>: flex;</span></span><br><span class="line"><span class="css">    <span class="attribute">justify-content</span>: center;</span></span><br><span class="line"><span class="css">    <span class="attribute">align-items</span>: center;</span></span><br><span class="line"><span class="css">&#125;</span></span><br><span class="line"><span class="css"><span class="selector-class">.box</span> &#123;</span></span><br><span class="line"><span class="css">  <span class="attribute">width</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">  <span class="attribute">height</span>: <span class="number">50px</span>;</span></span><br><span class="line"><span class="css">&#125;</span></span><br><span class="line"><span class="css"></span><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">&quot;box&quot;</span>&gt;</span><span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="css-如何实现左侧固定-300px，右侧自适应的布局"><a href="#css-如何实现左侧固定-300px，右侧自适应的布局" class="headerlink" title="css 如何实现左侧固定 300px，右侧自适应的布局"></a>css 如何实现左侧固定 300px，右侧自适应的布局</h2><p>使用 <code>flex</code> 布局，左侧 <code>300px</code>，右侧 <code>flex-grow: 1</code>：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.container</span> &#123;</span><br><span class="line">  <span class="attribute">display</span>: flex;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.left</span> &#123;</span><br><span class="line">  <span class="attribute">flex-basis</span>: <span class="number">300px</span>;</span><br><span class="line">  <span class="attribute">flex-shrink</span>: <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.main</span> &#123;</span><br><span class="line">  <span class="attribute">flex-grow</span>: <span class="number">1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>如果只使用 Grid 布局，则代码会更加简单，只需要控制容器的 CSS 属性：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.container</span> &#123;</span><br><span class="line">  <span class="attribute">display</span>: grid;</span><br><span class="line">  grid-template-<span class="attribute">columns</span>: <span class="number">300px</span> <span class="number">1</span>fr;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>使用 calc 方法 ：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.left</span> &#123;</span><br><span class="line">  <span class="attribute">width</span>:<span class="number">330px</span>;</span><br><span class="line">&#125; </span><br><span class="line"><span class="selector-class">.main</span> &#123;</span><br><span class="line">  <span class="attribute">width</span>: <span class="built_in">calc</span>(<span class="number">100%</span> - <span class="number">330px</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="css-隐藏页面中某个元素的几种方法"><a href="#css-隐藏页面中某个元素的几种方法" class="headerlink" title="css 隐藏页面中某个元素的几种方法"></a>css 隐藏页面中某个元素的几种方法</h2><ul>
<li><p>display:none</p>
<p>通过 CSS 操控 display，移出文档流</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">display</span>: none;</span><br></pre></td></tr></table></figure></li>
<li><p>opacity: 0</p>
<p>透明度为 0，仍在文档流中，当作用于其上的事件(如点击)仍有效</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">opacity</span>: <span class="number">0</span>;</span><br></pre></td></tr></table></figure></li>
<li><p>visibility: hidden</p>
<p>透明度为 0，仍在文档流中，但作用于其上的事件(如点击)无效，这也是 visibility:hidden 与 opacity: 0 的区别</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">visibility</span>: hidden;</span><br></pre></td></tr></table></figure></li>
<li><p>content-visibility</p>
<p>移出文档流，但是再次显示时消耗性能低</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">content</span>-<span class="attribute">visibility</span>: hidden;</span><br></pre></td></tr></table></figure></li>
<li><p>绝对定位于当前页面的不可见位置</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">position</span>: absolute;</span><br><span class="line"><span class="attribute">top</span>: -<span class="number">9000px</span>;</span><br><span class="line"><span class="attribute">left</span>: -<span class="number">9000px</span>;</span><br></pre></td></tr></table></figure></li>
<li><p>字体大小设置为 0</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">font-size</span>: <span class="number">0</span>;</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="css-中’-’-与-‘-’-选择器有什么不同"><a href="#css-中’-’-与-‘-’-选择器有什么不同" class="headerlink" title="css 中’+’ 与 ‘~’ 选择器有什么不同"></a>css 中’+’ 与 ‘~’ 选择器有什么不同</h2><ul>
<li>+ 选择器匹配紧邻的兄弟元素</li>
<li>~ 选择器匹配随后的所有兄弟元素</li>
</ul>
<h2 id="css-中关于选择器的权重"><a href="#css-中关于选择器的权重" class="headerlink" title="css 中关于选择器的权重"></a>css 中关于选择器的权重</h2><p><code>css specificity</code> 即 css 中关于选择器的权重，以下三种类型的选择器依次下降</p>
<ul>
<li><p><code>id</code> 选择器，如 #app</p>
</li>
<li><p><code>class</code> 、<code>attribute</code> 与 <code>pseudo-classes</code> 选择器，如 <code>.header</code>、[type=”radio”] 与 <code>:hover</code></p>
</li>
<li><p>type 标签选择器和伪元素选择器，如 <code>h1</code>、<code>p</code> 和 <code>::before</code></p>
</li>
</ul>
<p>其中通配符选择器 <code>*</code>，组合选择器 <code>+ ~ &gt;</code>，否定伪类选择器 <code>:not()</code> 对优先级无影响</p>
<p>另有内联样式 <code>&lt;div class=&quot;foo&quot; style=&quot;color: red;&quot;&gt;&lt;/div&gt;</code> 及 <code>!important</code>(最高) 具有更高的权重</p>
<h2 id="flex-布局中的-flex-basis-与-width-有何区别"><a href="#flex-布局中的-flex-basis-与-width-有何区别" class="headerlink" title="flex 布局中的 flex-basis 与 width 有何区别"></a>flex 布局中的 flex-basis 与 width 有何区别</h2><ol>
<li>当 <code>flex-direction</code> 为 <code>column</code> 时，主轴为纵轴，此时 <code>flex-basis</code> 与 <code>height</code> 对应</li>
<li><code>flex-basis</code> 的值为理想情况，而在实际情况中可能被压缩</li>
</ol>
<h2 id="css-如何自定义滚动条的样式"><a href="#css-如何自定义滚动条的样式" class="headerlink" title="css 如何自定义滚动条的样式"></a>css 如何自定义滚动条的样式</h2><p>滚动条相关样式都是伪元素，以 scrollbar 打头，有以下伪元素，从 -webkit 中可见兼容性一般，不过无所谓，现在Chrome 浏览器占大头</p>
<ul>
<li>::-webkit-scrollbar — 整个滚动条.<br>::-webkit-scrollbar-button — 滚动条上的按钮 (上下箭头).</li>
<li>::-webkit-scrollbar-thumb — 滚动条上的滚动滑块.</li>
<li>::-webkit-scrollbar-track — 滚动条轨道.</li>
<li>::-webkit-scrollbar-track-piece — 滚动条没有滑块的轨道部分.</li>
<li>::-webkit-scrollbar-corner — 当同时有垂直滚动条和水平滚动条时交汇的部分.</li>
<li>::-webkit-resizer — 某些元素的 corner 部分的部分样式(例:textarea 的可拖动按钮).</li>
</ul>
<p>但其实最常用的是以下几个伪元素：滚动条、滑块、轨道，如下滚动条设置成功</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">::-webkit-scrollbar &#123;</span><br><span class="line">  width: <span class="number">6px</span>;</span><br><span class="line">  <span class="attribute">height</span>: <span class="number">6px</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">::-webkit-scrollbar-track &#123;</span><br><span class="line">  border-radius: <span class="number">3px</span>;</span><br><span class="line">  <span class="attribute">background</span>: <span class="built_in">rgba</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line">  <span class="attribute">box-shadow</span>: inset <span class="number">0</span> <span class="number">0</span> <span class="number">5px</span> <span class="built_in">rgba</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0.08</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">::-webkit-scrollbar-thumb &#123;</span><br><span class="line">  border-radius: <span class="number">3px</span>;</span><br><span class="line">  <span class="attribute">background</span>: <span class="built_in">rgba</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>);</span><br><span class="line">  <span class="attribute">box-shadow</span>: inset <span class="number">0</span> <span class="number">0</span> <span class="number">10px</span> <span class="built_in">rgba</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0.2</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="css-如何实现容器中子元素三个三列布局，子元素两个则两列布局"><a href="#css-如何实现容器中子元素三个三列布局，子元素两个则两列布局" class="headerlink" title="css 如何实现容器中子元素三个三列布局，子元素两个则两列布局"></a>css 如何实现容器中子元素三个三列布局，子元素两个则两列布局</h2><blockquote>
<p>问题描述：<br>容器中有三个及以上元素，三列布局<br>容器只有两个元素，两列布局平分<br>容器只有一个元素，一列布局全占</p>
</blockquote>
<p>可以使用 flex 布局或者是 grid 布局</p>
<p>关健在于如何判断有多少元素。我们只需要判断有 1 个，有 2 个的情况，其他都是三列布局</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 有1个元素 */</span></span><br><span class="line"><span class="selector-class">.item</span><span class="selector-pseudo">:nth-last-child</span>(<span class="number">1</span>)<span class="selector-pseudo">:first</span>-child &#123;</span><br><span class="line">  <span class="attribute">flex</span>: <span class="number">1</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.item</span><span class="selector-pseudo">:nth-last-child</span>(<span class="number">1</span>)<span class="selector-pseudo">:first</span>-child ~ <span class="selector-class">.item</span> &#123;</span><br><span class="line">  <span class="attribute">flex</span>: <span class="number">1</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 有2个元素 */</span></span><br><span class="line"><span class="selector-class">.item</span><span class="selector-pseudo">:nth-last-child</span>(<span class="number">2</span>)<span class="selector-pseudo">:first</span>-child &#123;</span><br><span class="line">  <span class="attribute">flex</span>: <span class="number">1</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="selector-class">.item</span><span class="selector-pseudo">:nth-last-child</span>(<span class="number">2</span>)<span class="selector-pseudo">:first</span>-child ~ <span class="selector-class">.item</span> &#123;</span><br><span class="line">  <span class="attribute">flex</span>: <span class="number">1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="css-网站设置字体时，如何设置优先使用系统默认字体"><a href="#css-网站设置字体时，如何设置优先使用系统默认字体" class="headerlink" title="css 网站设置字体时，如何设置优先使用系统默认字体"></a>css 网站设置字体时，如何设置优先使用系统默认字体</h2><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">font-family</span>: system-ui;</span><br></pre></td></tr></table></figure>

<p><code>system-ui</code> 将会自动选取系统默认字体作为字体</p>
<h2 id="css-如何设置方格背景"><a href="#css-如何设置方格背景" class="headerlink" title="css 如何设置方格背景"></a>css 如何设置方格背景</h2><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">background</span>: </span><br><span class="line"><span class="built_in">linear-gradient</span>(<span class="number">90deg</span>, <span class="built_in">rgba</span>(<span class="number">200</span>, <span class="number">200</span>, <span class="number">200</span>, <span class="number">0.1</span>) <span class="number">3%</span>, transparent <span class="number">0</span>),</span><br><span class="line"><span class="built_in">linear-gradient</span>(<span class="built_in">rgba</span>(<span class="number">200</span>, <span class="number">200</span>, <span class="number">200</span>, <span class="number">0.1</span>) <span class="number">3%</span>, transparent <span class="number">0</span>);</span><br><span class="line"><span class="attribute">background-size</span>: <span class="number">20px</span> <span class="number">20px</span>;</span><br></pre></td></tr></table></figure>

<h2 id="伪类和伪元素的区别"><a href="#伪类和伪元素的区别" class="headerlink" title="伪类和伪元素的区别"></a>伪类和伪元素的区别</h2><p>引入伪类和伪元素概念是为了格式化文档树以外的信息。也就是说，伪类和伪元素是用修饰不在文档树中的部分，比如，一句话中的第一个字母，或者是列表中的第一个元素。</p>
<p><strong>伪类用于当已有的元素处于某个状态时，为其添加对应的样式，这个状态是根据用户行为动态变化的</strong>。比如说，当用户悬停在指定的元素时，我们可以通过 <code>:hover</code> 来描述这个元素的状态。</p>
<p><strong>伪元素用于创建一些不在文档树中的元素，并为其添加样式</strong>。它们允许我们为元素的某些部分设置样式。比如说，我们可以通过 <code>::before</code> 来在一个元素前增加一些文本，并为这些文本添加样式。虽然用户可以看到这些文本，但是这些文本实际上不在文档树中。</p>
<p>有时你会发现伪元素使用了两个冒号（::）而不是一个冒号（:）。这是 <code>CSS3</code> 的一部分，并尝试区分伪类和伪元素。大多数浏览器都支持这两个值。按照规则应该使用（::）而不是（:），从而区分伪类和伪元素。但是，由于在旧版本的W3C规范并未对此进行特别区分，因此目前绝大多数的浏览器都支持使用这两种方式表示伪元素。</p>
<h2 id="css定位"><a href="#css定位" class="headerlink" title="css定位"></a>css定位</h2><ul>
<li>relative：生成相对定位的元素，相对于其元素本身所在正常位置进行定位。元素所占的空间还是在原来的位置</li>
<li>absolute：绝对定位，相对于值不为static的第一个父元素的padding box进行定位，也可以理解为离自己这一级元素最近的<br>一级 position 设置为 absolute 或者 relative 的父元素的padding box的左上角为原点的。</li>
<li>static：默认定位</li>
<li>fixed：固定定位，包含元素是浏览器窗口，可以设置 <code>left:0;right:0</code>,将容器宽度占满窗口，也可以设置 <code>top:0;bottom:0</code> 将容器高度占满窗口</li>
<li>sticky：相当于 relative 和 fixed 结合体</li>
</ul>

  </div>
</article>



        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/categories/">分类</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a target="_blank" rel="noopener" href="http://github.com/twitzz">项目</a></li>
         
          <li><a href="/about/">关于</a></li>
         
          <li><a href="/search/">搜索</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#css%E9%80%89%E6%8B%A9%E5%99%A8%E6%9C%89%E5%93%AA%E4%BA%9B"><span class="toc-number">1.</span> <span class="toc-text">css选择器有哪些</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#display-%E6%9C%89%E5%93%AA%E4%BA%9B%E5%80%BC%EF%BC%9F%E8%AF%B4%E6%98%8E%E4%BB%96%E4%BB%AC%E7%9A%84%E4%BD%9C%E7%94%A8"><span class="toc-number">2.</span> <span class="toc-text">display 有哪些值？说明他们的作用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%8A%A8%E7%94%BB%E4%B8%8E-js-%E5%8A%A8%E7%94%BB%E5%93%AA%E4%B8%AA%E6%80%A7%E8%83%BD%E6%9B%B4%E5%A5%BD"><span class="toc-number">3.</span> <span class="toc-text">css 动画与 js 动画哪个性能更好</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%AF%B9%E4%B8%80%E4%B8%AA%E9%9D%9E%E5%AE%9A%E9%95%BF%E5%AE%BD%E7%9A%84%E5%9D%97%E7%8A%B6%E5%85%83%E7%B4%A0%E5%A6%82%E4%BD%95%E5%81%9A%E5%9E%82%E7%9B%B4%E6%B0%B4%E5%B9%B3%E5%B1%85%E4%B8%AD"><span class="toc-number">4.</span> <span class="toc-text">css 对一个非定长宽的块状元素如何做垂直水平居中</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E7%94%BB%E4%B8%80%E4%B8%AA%E4%B8%89%E8%A7%92%E5%BD%A2"><span class="toc-number">5.</span> <span class="toc-text">css 如何画一个三角形</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AE%E5%A4%9A%E8%A1%8C%E8%B6%85%E5%87%BA%E6%98%BE%E7%A4%BA%E7%9C%81%E7%95%A5%E5%8F%B7"><span class="toc-number">6.</span> <span class="toc-text">css 如何设置多行超出显示省略号</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AE%E4%B8%80%E8%A1%8C%E8%B6%85%E5%87%BA%E6%98%BE%E7%A4%BA%E7%9C%81%E7%95%A5%E5%8F%B7"><span class="toc-number">7.</span> <span class="toc-text">css 如何设置一行超出显示省略号</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%AF%B9%E4%B8%80%E4%B8%AA%E9%9D%9E%E5%AE%9A%E9%95%BF%E5%AE%BD%E7%9A%84%E5%9D%97%E7%8A%B6%E5%85%83%E7%B4%A0%E5%A6%82%E4%BD%95%E5%81%9A%E5%9E%82%E7%9B%B4%E6%B0%B4%E5%B9%B3%E5%B1%85%E4%B8%AD-1"><span class="toc-number">8.</span> <span class="toc-text">css 对一个非定长宽的块状元素如何做垂直水平居中</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0%E7%9A%84%E6%B0%B4%E5%B9%B3%E5%9E%82%E7%9B%B4%E5%B1%85%E4%B8%AD"><span class="toc-number">9.</span> <span class="toc-text">css 如何实现一个元素的水平垂直居中</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E5%B7%A6%E4%BE%A7%E5%9B%BA%E5%AE%9A-300px%EF%BC%8C%E5%8F%B3%E4%BE%A7%E8%87%AA%E9%80%82%E5%BA%94%E7%9A%84%E5%B8%83%E5%B1%80"><span class="toc-number">10.</span> <span class="toc-text">css 如何实现左侧固定 300px，右侧自适应的布局</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E9%9A%90%E8%97%8F%E9%A1%B5%E9%9D%A2%E4%B8%AD%E6%9F%90%E4%B8%AA%E5%85%83%E7%B4%A0%E7%9A%84%E5%87%A0%E7%A7%8D%E6%96%B9%E6%B3%95"><span class="toc-number">11.</span> <span class="toc-text">css 隐藏页面中某个元素的几种方法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E4%B8%AD%E2%80%99-%E2%80%99-%E4%B8%8E-%E2%80%98-%E2%80%99-%E9%80%89%E6%8B%A9%E5%99%A8%E6%9C%89%E4%BB%80%E4%B9%88%E4%B8%8D%E5%90%8C"><span class="toc-number">12.</span> <span class="toc-text">css 中’+’ 与 ‘~’ 选择器有什么不同</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E4%B8%AD%E5%85%B3%E4%BA%8E%E9%80%89%E6%8B%A9%E5%99%A8%E7%9A%84%E6%9D%83%E9%87%8D"><span class="toc-number">13.</span> <span class="toc-text">css 中关于选择器的权重</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#flex-%E5%B8%83%E5%B1%80%E4%B8%AD%E7%9A%84-flex-basis-%E4%B8%8E-width-%E6%9C%89%E4%BD%95%E5%8C%BA%E5%88%AB"><span class="toc-number">14.</span> <span class="toc-text">flex 布局中的 flex-basis 与 width 有何区别</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E8%87%AA%E5%AE%9A%E4%B9%89%E6%BB%9A%E5%8A%A8%E6%9D%A1%E7%9A%84%E6%A0%B7%E5%BC%8F"><span class="toc-number">15.</span> <span class="toc-text">css 如何自定义滚动条的样式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E5%AE%B9%E5%99%A8%E4%B8%AD%E5%AD%90%E5%85%83%E7%B4%A0%E4%B8%89%E4%B8%AA%E4%B8%89%E5%88%97%E5%B8%83%E5%B1%80%EF%BC%8C%E5%AD%90%E5%85%83%E7%B4%A0%E4%B8%A4%E4%B8%AA%E5%88%99%E4%B8%A4%E5%88%97%E5%B8%83%E5%B1%80"><span class="toc-number">16.</span> <span class="toc-text">css 如何实现容器中子元素三个三列布局，子元素两个则两列布局</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E7%BD%91%E7%AB%99%E8%AE%BE%E7%BD%AE%E5%AD%97%E4%BD%93%E6%97%B6%EF%BC%8C%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AE%E4%BC%98%E5%85%88%E4%BD%BF%E7%94%A8%E7%B3%BB%E7%BB%9F%E9%BB%98%E8%AE%A4%E5%AD%97%E4%BD%93"><span class="toc-number">17.</span> <span class="toc-text">css 网站设置字体时，如何设置优先使用系统默认字体</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css-%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AE%E6%96%B9%E6%A0%BC%E8%83%8C%E6%99%AF"><span class="toc-number">18.</span> <span class="toc-text">css 如何设置方格背景</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BC%AA%E7%B1%BB%E5%92%8C%E4%BC%AA%E5%85%83%E7%B4%A0%E7%9A%84%E5%8C%BA%E5%88%AB"><span class="toc-number">19.</span> <span class="toc-text">伪类和伪元素的区别</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#css%E5%AE%9A%E4%BD%8D"><span class="toc-number">20.</span> <span class="toc-text">css定位</span></a></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.facebook.com/sharer.php?u=https://danyuan30.gitee.io/2022/03/05/interview/css/"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://twitter.com/share?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&text=css面试题合集"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.linkedin.com/shareArticle?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&title=css面试题合集"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://pinterest.com/pin/create/bookmarklet/?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&is_video=false&description=css面试题合集"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=css面试题合集&body=Check out this article: https://danyuan30.gitee.io/2022/03/05/interview/css/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://getpocket.com/save?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&title=css面试题合集"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://reddit.com/submit?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&title=css面试题合集"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.stumbleupon.com/submit?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&title=css面试题合集"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://digg.com/submit?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&title=css面试题合集"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="http://www.tumblr.com/share/link?url=https://danyuan30.gitee.io/2022/03/05/interview/css/&name=css面试题合集&description="><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" target="_blank" rel="noopener" href="https://news.ycombinator.com/submitlink?u=https://danyuan30.gitee.io/2022/03/05/interview/css/&t=css面试题合集"><i class="fab fa-hacker-news fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> 菜单</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> 目录</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> 分享</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> 返回顶部</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy;
    
    
    2021-2022
    柯里的语法糖
  </div>
  <div class="footer-right">
    <nav>
      <ul>
        <!--
       --><li><a href="/">首页</a></li><!--
     --><!--
       --><li><a href="/tags/">标签</a></li><!--
     --><!--
       --><li><a href="/categories/">分类</a></li><!--
     --><!--
       --><li><a href="/archives/">归档</a></li><!--
     --><!--
       --><li><a target="_blank" rel="noopener" href="http://github.com/twitzz">项目</a></li><!--
     --><!--
       --><li><a href="/about/">关于</a></li><!--
     --><!--
       --><li><a href="/search/">搜索</a></li><!--
     -->
      </ul>
    </nav>
  </div>
</footer>

    </div>
    <!-- styles -->



  <link rel="preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css" crossorigin="anonymous" onload="this.onload=null;this.rel='stylesheet'"/>


    <!-- jquery -->
 
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" crossorigin="anonymous"></script> 




<!-- clipboard -->

  
    <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.7/clipboard.min.js" crossorigin="anonymous"></script> 
  
  <script type="text/javascript">
  $(function() {
    // copy-btn HTML
    var btn = "<span class=\"btn-copy tooltipped tooltipped-sw\" aria-label=\"复制到粘贴板!\">";
    btn += '<i class="far fa-clone"></i>';
    btn += '</span>'; 
    // mount it!
    $(".highlight table").before(btn);
    var clip = new ClipboardJS('.btn-copy', {
      text: function(trigger) {
        return Array.from(trigger.nextElementSibling.querySelectorAll('.code')).reduce((str,it)=>str+it.innerText+'\n','')
      }
    });
    clip.on('success', function(e) {
      e.trigger.setAttribute('aria-label', "复制成功!");
      e.clearSelection();
    })
  })
  </script>


<script src="/js/main.js"></script>

<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

<!-- Cloudflare Analytics -->

<!-- Umami Analytics -->

<!-- Disqus Comments -->

<!-- utterances Comments -->

</body>
</html>
